<?php
namespace Youjiu\Controller;
use Think\Controller;

class RightController extends Controller{
	
	function __construct(){
		parent::__construct();
		header("Content-type:text/html; charset=utf-8");
	}
	
	function index(){
		$hero_list	= M('hero_right')->select();
		$this->assign("hero_list", $hero_list);
		$this->display("index");
	}
	
	function addHero(){
		if($_GET['ops_type'] == "add"){
			$this->display("hero_add");
		}else if($_GET['ops_type'] == "save"){
			$data	= $_GET;
			$status	= M('hero_right')->data($data)->filter("strip_tags")->add();
			
			if(!$status){
				$this->error("删除失败,请重试！");
				return 0;
			}
			$this->redirect("Youjiu/Right/index");
		}else{
			$data	= $_GET;
			$data['skill_name']	= array_filter(explode(" ", $data['skill_name']));
			$data['skill_img']	= array_filter(explode(" ", $data['skill_img']));
			
			$data['good_hero_name']	= array_filter(explode(" ", $data['good_hero_name']));
			$data['good_hero_img']	= array_filter(explode(" ", $data['good_hero_img']));
			$data['good_hero_desc']	= array_filter(explode(" ", $data['good_hero_desc']));
			$data['good_hero_url']	= array_filter(explode(" ", $data['good_hero_url']));
			
			$data['bad_hero_name']	= array_filter(explode(" ", $data['bad_hero_name']));
			$data['bad_hero_img']	= array_filter(explode(" ", $data['bad_hero_img']));
			$data['bad_hero_desc']	= array_filter(explode(" ", $data['bad_hero_desc']));
			$data['bad_hero_url']	= array_filter(explode(" ", $data['bad_hero_url']));
			
			$this->assign("data", $data);
			$this->display("hero_preview");
		}
	}
	
	function detailHero(){
		$hero_id	= $_REQUEST['hero_id'];
		$hero	= M('hero_right')->where('hero_id = '.(int)$hero_id)->find();

		$hero['skill_name']		= array_filter(explode(" ", $hero['skill_name']));
		$hero['skill_img']		= array_filter(explode(" ", $hero['skill_img']));
		$hero['good_hero_name']	= array_filter(explode(" ", $hero['good_hero_name']));
		$hero['good_hero_img']	= array_filter(explode(" ", $hero['good_hero_img']));
		$hero['good_hero_desc']	= array_filter(explode(" ", $hero['good_hero_desc']));
		$hero['good_hero_url']	= array_filter(explode(" ", $hero['good_hero_url']));
			
		$hero['bad_hero_name']	= array_filter(explode(" ", $hero['bad_hero_name']));
		$hero['bad_hero_img']	= array_filter(explode(" ", $hero['bad_hero_img']));
		$hero['bad_hero_desc']	= array_filter(explode(" ", $hero['bad_hero_desc']));
		$hero['bad_hero_url']	= array_filter(explode(" ", $hero['bad_hero_url']));
		
		$this->assign("data", $hero);
		$this->display("hero_preview");
	}
	
	function deleteHero(){
		$hero_id	= $_REQUEST['hero_id'];
		$status	= M('hero_right')->where("hero_id = ".(int)$hero_id)->delete();
		
		if(!$status){
			$this->error("删除失败,请重试！");
			return 0;
		}
		$this->redirect("Youjiu/Right/index");
	}
	
	function outXML(){
		set_time_limit(600);
		$_hero_list	= M('hero_right')->select();
		$hero_list	= array();
		foreach($_hero_list as $hero){
			$hero['skill_name']		= array_filter(explode(" ", $hero['skill_name']));
			$hero['skill_img']		= array_filter(explode(" ", $hero['skill_img']));
			$hero['good_hero_name']	= array_filter(explode(" ", $hero['good_hero_name']));
			$hero['good_hero_img']	= array_filter(explode(" ", $hero['good_hero_img']));
			$hero['good_hero_desc']	= array_filter(explode(" ", $hero['good_hero_desc']));
			$hero['good_hero_url']	= array_filter(explode(" ", $hero['good_hero_url']));
				
			$hero['bad_hero_name']	= array_filter(explode(" ", $hero['bad_hero_name']));
			$hero['bad_hero_img']	= array_filter(explode(" ", $hero['bad_hero_img']));
			$hero['bad_hero_desc']	= array_filter(explode(" ", $hero['bad_hero_desc']));
			$hero['bad_hero_url']	= array_filter(explode(" ", $hero['bad_hero_url']));
			
			array_push($hero_list , $hero);
		}
		
		$this->assign("hero_list", $hero_list);
		$this->display("./Public/Template/right.xml", "utf-8", "text/xml");
	}
	
}